/*
 * File Name：PayResult.java
 * Copyright：Copyright 2008-2014 CiWong.Inc. All Rights Reserved.
 * Description： PayResult.java
 * Modify By：jejun
 * Modify Date：2014-6-12
 * Modify Type：Add
 */
package com.ciwong.mobilepay.view;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.support.v4.content.res.ResourcesCompat;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.Gravity;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ciwong.mobilelib.R;
import com.ciwong.mobilepay.adapter.PayMethodAdapter;
import com.ciwong.mobilepay.util.PayUtil;

/**
 * 支付结果
 * 
 * @author jejun
 * @version ciwong v.1.0 2014-6-12
 * @since ciwong v.1.0
 */
public class PayResult extends LinearLayout
{
    public static final int payResult = 0x1f1;

    public static final int payResultCommodityName = 0x1f2;

    public static final int payResultCommodityNumber = 0x1f3;

    public static final int payResultComplete = 0x1f4;

    private static final int TEXT_COLOR = Color.rgb(93, 93, 93);

    public PayResult(Context context)
    {
        super(context);
        init();
    }

    private void init()
    {
        setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.FILL_PARENT));
        setOrientation(LinearLayout.VERTICAL);
        DisplayMetrics dm = getResources().getDisplayMetrics();

        TextView payResult = new TextView(getContext());
        payResult.setId(PayResult.payResult);
        LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT);
        lp.bottomMargin = (int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 5, dm);
        payResult.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
        payResult.getPaint().setFakeBoldText(true);
        payResult.setGravity(Gravity.CENTER_VERTICAL);
        payResult.setTextColor(Color.rgb(65, 65, 65));
        addView(payResult);
        payResult.setLayoutParams(lp);

        LinearLayout container = new LinearLayout(getContext());
        lp = new LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT);
        Drawable backgound = ResourcesCompat.getDrawable(getResources(), R.drawable.commodity_info_bg,null);
        container.setBackgroundDrawable(backgound);
        lp.bottomMargin = (int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 10, dm);
        container.setOrientation(LinearLayout.VERTICAL);
        addView(container);
        int padding = (int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 10, dm);
        container.setPadding(padding, padding, padding, padding);
        container.setLayoutParams(lp);

        TextView payResultCommodityName = new TextView(getContext());
        payResultCommodityName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
        payResultCommodityName.setId(PayResult.payResultCommodityName);
        container.addView(payResultCommodityName);
        payResultCommodityName.setLayoutParams(new LayoutParams(
                LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        payResultCommodityName.setTextColor(TEXT_COLOR);

        TextView payResultCommodityNumber = new TextView(getContext());
        payResultCommodityNumber.setId(PayResult.payResultCommodityNumber);
        payResultCommodityNumber.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
        container.addView(payResultCommodityNumber);
        payResultCommodityNumber.setLayoutParams(new LayoutParams(
                LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        payResultCommodityNumber.setTextColor(TEXT_COLOR);

        Button payResultComplete = new Button(getContext());
        payResultComplete.setId(PayResult.payResultComplete);
        payResultComplete.setText("OK");
        payResultComplete.setTextColor(Color.WHITE);
        payResultComplete.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        payResultComplete.setMinimumHeight((int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 40, dm));

        // Drawable enabled = PayUtil.getDrawableFromJar(
        // "/images_mobilepay/pay_btn_enabled.9.png",
        // PayMethodAdapter.class);
        Drawable press = ResourcesCompat.getDrawable(getResources(),R.mipmap.pay_btn_press,null);
        Drawable normal = ResourcesCompat.getDrawable(getResources(),R.mipmap.pay_btn_normal,null);
        Drawable selector = PayUtil.getDrawableSelector(new int[][]{
                {android.R.attr.state_pressed}, {0}}, new Drawable[]{press,
                normal});
        payResultComplete.setBackgroundDrawable(selector);

        addView(payResultComplete);
        payResultComplete.setLayoutParams(new LayoutParams(
                LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    }
}
